# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import traceback
import json
from django.http import JsonResponse
from utils.logger import Md_Debug
from app.manage.recourseManage.common.manage_query import RecourseManageDB
from app.manage.recourseManage.common.manage_add_edit_delete import RecourseEditDB
from django.views.decorators.csrf import csrf_exempt
from utils.response_utils import response_change

RecourseManageDB = RecourseManageDB()
RecourseEditDB = RecourseEditDB()


@csrf_exempt
def recourse_list(request):
    """人力资源列表"""
    try:
        body = json.loads(request.body)
        data = RecourseManageDB.recourse_list(body)
    except Exception as e:
        Md_Debug.info(traceback.format_exc(e))
        print(traceback.format_exc(e))
    response = JsonResponse(data)
    return response_change(response)


@csrf_exempt
def edit_recourse(request):
    """编辑人力信息"""
    try:
        body = json.loads(request.body)
        data = RecourseManageDB.edit_recourse(body)
    except Exception as e:
        Md_Debug.info(traceback.format_exc(e))
        print(traceback.format_exc(e))
    response = JsonResponse(data)
    return response_change(response)


@csrf_exempt
def add_recourse(request):
    """添加人力资源"""
    try:
        body = json.loads(request.body)
        data = RecourseEditDB.add_recourse(body)
    except Exception as e:
        Md_Debug.info(traceback.format_exc(e))
        print(traceback.format_exc(e))
    response = JsonResponse(data)
    return response_change(response)


@csrf_exempt
def edit_recourse(request):
    """编辑人力资源"""
    try:
        body = json.loads(request.body)
        data = RecourseEditDB.edit_recourse(body)
    except Exception as e:
        Md_Debug.info(traceback.format_exc(e))
        print(traceback.format_exc(e))
    response = JsonResponse(data)
    return response_change(response)


@csrf_exempt
def del_recourse(request):
    """删除人力资源"""
    try:
        body = json.loads(request.body)
        data = RecourseEditDB.del_recourse(body)
    except Exception as e:
        Md_Debug.info(traceback.format_exc(e))
        print(traceback.format_exc(e))
    response = JsonResponse(data)
    return response_change(response)